package com.zzptc.lxy.mybook;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.zzptc.lxy.mybook.Bean.User;

public class RegisterActivity extends AppCompatActivity {

    private EditText usnedit, psdedit;
    private Button registerbtn;

    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        initView();
        setListener();

    }

    private void setListener() {

//        注册
        registerbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String usn = usnedit.getText().toString().trim();//获取账号密码
                String psd = psdedit.getText().toString().trim();

                User user = new User();//新用户
                user.setUsername(usn);//用户名
                user.setPassword(psd);//密码
                user.save();//保存用户
                if (user.save()) {//如果保存了
                    Toast.makeText(RegisterActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
                    startActivity(new Intent(RegisterActivity.this, LoginActivity.class));//跳转到登录页面


                }
            }
        });
    }

    private void initView() {
        usnedit = findViewById(R.id.usnedit);
        psdedit = findViewById(R.id.psdedit);
        registerbtn = findViewById(R.id.registerbtn);


    }
}